package cn.edu.zafu.bigdata.lmr;


class StaticDemo {
        // 静态变量，用于计数类的实例创建次数
        static int count = 0;

        // 实例变量，用于存储每个实例的唯一编号
        int id;

        // 静态初始化块，当类加载时执行
        static {
            System.out.println("Static block executed");
            count = 0;
        }

        // 实例初始化块，每次创建新实例时执行
        {
            System.out.println("Instance block executed");
            this.id = count;
            count++;
        }

        // 构造函数，用于创建实例
        public StaticDemo() {
            System.out.println("Constructor executed for ID: " + this.id);
        }

        // 静态方法，用于打印当前创建了多少个实例
        public static void displayCount() {
            System.out.println("Total number of instances created: " + count);
        }
    }
class TestStaticDemo {
    public static void main(String[] args) {
        // 创建多个 StaticDemo 类的实例
        System.out.println("Creating instances:");
        StaticDemo demo1 = new StaticDemo();
        StaticDemo demo2 = new StaticDemo();
        StaticDemo demo3 = new StaticDemo();

        // 调用 StaticDemo.displayCount() 静态方法，验证实例创建次数
        StaticDemo.displayCount();
    }
}